package com.gua.jbs.serviceImpl;

import java.util.Date;

import org.apache.log4j.Logger;

import com.gua.jbs.bean.CustomerBean;
import com.gua.jbs.dao.IBillDao;
import com.gua.jbs.dao.ICustomerDao;
import com.gua.jbs.daoImpl.BillDao;
import com.gua.jbs.daoImpl.CustomerDao;
import com.gua.jbs.pojo.Jbscit;
import com.gua.jbs.service.ICustomerService;
import com.gua.jbs.utility.ApplicationException;
import com.gua.jbs.utility.ExceptionMessage;

public class CustomerService extends BaseService implements ICustomerService {

	private static final Logger logger = Logger
			.getLogger(CustomerService.class);

	public String addCustomerForBill(CustomerBean customerBean)
			throws ApplicationException {
		boolean isSaved = false;
		String pk = null;

		if (customerBean != null) {
			Jbscit jbscit = new Jbscit();
			jbscit.setCustFName(customerBean.getName());
			jbscit.setCustLName(customerBean.getName());
			jbscit.setCustMobile(customerBean.getContactNo());
			jbscit.setCustAddress(customerBean.getAddress());
			jbscit.setCustExtraAddr(null);
			jbscit.setCustLandmark(null);
			jbscit.setCustHomePhone(customerBean.getContactNo());
			jbscit.setCustEmailAddr(customerBean.getEmailAddress());
			jbscit.setCustCity(null);
			jbscit.setCustState(null);
			jbscit.setCustCountry(null);
			jbscit.setActive(true);
			jbscit.setCreateDate(new Date());
			jbscit.setModifyDate(new Date());
			jbscit.setExtrafield1(null);
			jbscit.setExtrafield2(null);
			jbscit.setExtrafield3(null);
			jbscit.setCreatedBy("Yogesh");
			jbscit.setCreatedBy("Yogesh");
			ICustomerDao customerDao = new CustomerDao();
			// Call the DAO layer to save the customer
			try {
				pk = customerDao.saveCustomer(jbscit);
			} catch (ApplicationException ae) {
				throw ae;
			} catch (Exception e) {
				logger.error("CustomerService : addCustomerForBill() ----> "
						+ e.getMessage());
				throw new ApplicationException(
						ExceptionMessage.CUSTOMER_FOR_BILL_SAVE_UNABLE);
			}
		}
		return pk;
	}
}
